<?php
/**
 * String Length Rule
 * Determine if a string is between a minimum and maximum length
 * 
 * @package     Q-Validate
 * @subpackage  Rules
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id: Length.php 37 2010-12-23 02:38:44Z luke.visinoni $
 */
class Q_Rule_Length extends Q_Rule_Abstract {

    /**
     * The parameters that were passed to this rule
     */
    protected $_params = array(
        'min' => 0,
        'max' => null,
    );
    
    /**
     * Validate string length
     */
    public function isValid($value) {
    
        $length = strlen($value);
        if ($length >= $this->getParam('min')) {
            if ($this->getParam('max') == null) return true;
            else return !($length > $this->getParam('max'));
        }
        return false;
    
    }

}
